package com.movie.modules.api.controller;

import com.movie.common.utils.R;
import com.movie.modules.api.service.AppService;
import com.movie.modules.jf.entity.MovieCommentEntity;
import com.movie.modules.jf.entity.RelationEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author JF-PJJ
 */
@RestController
@RequestMapping("/api")
@Api(tags = "电影页面接口")
public class ApiMovieController {
    @Autowired
    private AppService appService;

    @GetMapping("/banner/movie")
    @ApiOperation("电影轮播列表")
    public R movieBanner(){
        return R.ok(appService.bannerList(2));
    }

    @GetMapping("/movie/type/list")
    @ApiOperation("电影类型列表")
    public R movieTypeList(){
        return R.ok(appService.typeList(1,null));
    }


    @GetMapping("/movie/list")
    @ApiOperation("电影列表")
    public R movieListPage(Integer page,Integer typeId){
        return R.ok().put("data",appService.movieListPage(page,typeId));
    }

    @GetMapping("/movie/info/{movieId}")
    @ApiOperation("电影详情")
    public R movieDetail(@PathVariable("movieId") Integer movieId){
        return appService.movieDetail(movieId);
    }

    @GetMapping("/movie/comment/list/{movieId}")
    @ApiOperation("电影影评列表")
    public R movieCommentList(@PathVariable("movieId") Integer movieId,Integer page){
        return R.ok().put("data",appService.movieCommentList(movieId,page));
    }

    @GetMapping("/actor/info/{actorId}")
    @ApiOperation("演员详情")
    public R actorDetail(@PathVariable("actorId") Integer actorId){
        return appService.actorDetail(actorId);
    }

    @PostMapping("/collect")
    @ApiOperation("收藏电影/关注演员或取消收藏/取消关注")
    public R collect(@RequestBody RelationEntity relation){
        appService.collect(relation);
        return R.ok();
    }

    @GetMapping("/movie/vip/{movieId}/{vipId}")
    @ApiOperation("当前用户是否收藏该电影")
    public R movieVip(@PathVariable("movieId") Integer movieId,@PathVariable("vipId") Integer vipId){
        return appService.movieVip(movieId, vipId);
    }

    @GetMapping("/actor/vip/{actorId}/{vipId}")
    @ApiOperation("当前用户是否收藏该电影")
    public R actorVip(@PathVariable("actorId") Integer actorId,@PathVariable("vipId") Integer vipId){
        return appService.actorVip(actorId, vipId);
    }

    @PostMapping("/comment/release")
    @ApiOperation("发布影评")
    public R saveComment(@RequestBody MovieCommentEntity comment){
        appService.saveComment(comment);
        return R.ok();
    }
}
